<template>
		<div class="panel panel-default  main-panel-right">
			<div class="box-header with-border">
				<h4 class="box-title">新建群发消息          
				</h4>
			</div>				 
			<div class="panel-container">
				<div class="panel-body">
						<form class="form-inline" @submit.prevent v-el:searchform>
							<div class="form-group">
								<label>组别：</label>
								<select class="form-control" v-el:group>
									<option value="{{group.id.id}}" v-for="group in subGroup">{{group.name}}</option>
								</select>										
							</div>		 

						</form>								
				</div>
			<style>
				.box-container {
					width:200px;
					margin: 10px auto;
				}	
			</style>
				<div class="panel-footer">					    
					<app-box v-ref:box></app-box>
					<div class="wizard-buttons" style="background:#fff">
						<div class="row">
							<div class="col-sm-11">
								<div class="text-center">
									<v-button theme="primary" @click="submit" class="col-sm-offset-1 pull-left">确认群发</v-button>									
								</div>
							</div>
						</div>
					</div>
				</div>																	

			</div> 
		</div>

</template>
<script>	
import Box from 'pages/partial/box.vue';
export default {
		components: {
			'app-box': Box
		},			
		data: () => ({
			subGroup: []
		}),	
		methods: {
			getSubGroup() {
				let self = this;
				self.$search({
					url: '/api/v1' + projectName_Url + '/wechat/subGroup/query.html'
				}).then(response => {	
					let data = response.content.groupList;
					self.$set("subGroup",data);
				}, error => {});				
			},
			submit() {			
				let self = this;
				if(this.$refs.box.valid()){
					let data = this.$refs.box.get();	
					data.groupId = this.$els.group.value;
					data.mchtId = localStorage.getItem('get_id');			
					if(data.msgType=='news') {
						data.msgType = 'mpnews'
					}
					self.$post({
						url: '/api/v1' + projectName_Url + '/wechat/mass/sendAll.html',
						data
					}).then(response => {	
						let message = {
							title:"操作提示",
							content:"群发操作成功"
						}
						Midway.alert(message);
						self.$refs.box.clear();
					}, error => {});					
				}							
		
			}
		},
		ready() {
				this.getSubGroup();
		}
}
</script>